// Sequelize初始化文件
const { Sequelize } = require("sequelize");
const dbConfig = require("../config/db.config.js");

// 创建Sequelize实例
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
  host: dbConfig.HOST,
  dialect: dbConfig.dialect,
  pool: {
    max: dbConfig.pool.max,
    min: dbConfig.pool.min,
    acquire: dbConfig.pool.acquire,
    idle: dbConfig.pool.idle
  }
});

// 测试连接
sequelize.authenticate()
  .then(() => {
    console.log("数据库连接成功!");
  })
  .catch(err => {
    console.error("数据库连接失败:", err.message);
  });

module.exports = sequelize;